package com.atguigu.gmall.mq.reveiver;

import com.atguigu.gmall.mq.config.DelayedMqConfig;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * @author: atguigu
 * @create: 2023-05-09 10:52
 */
@Slf4j
@Component
public class DelayMsgReceiver {


    /**
     * 监听延迟消息
     *
     * @param msg
     * @param channel
     * @param message
     */
    @SneakyThrows
    @RabbitListener(queues = {DelayedMqConfig.queue_delay_1})
    public void delayMsgReceiver(String msg, Channel channel, Message message) {
        if (StringUtils.isNotBlank(msg)) {
            log.info("基于延迟插件收到的延迟消息:{}", msg);
        }
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
